package com.teamfractal.fracdustry.common.integration.jei.categories;

import com.mojang.blaze3d.vertex.PoseStack;
import com.teamfractal.fracdustry.common.Fracdustry;
import com.teamfractal.fracdustry.common.block.init.FDBlocks;
import com.teamfractal.fracdustry.common.data.recipes.OreProcessorRecipe;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;

import javax.annotation.Nonnull;


public class OreProcessorRecipeCategory implements IRecipeCategory<OreProcessorRecipe> {

    public final static ResourceLocation UID = new ResourceLocation(Fracdustry.MODID, "ore_processor");
    public final static ResourceLocation BACKGROUND = new ResourceLocation(Fracdustry.MODID, "textures/gui/ore_processor/screen.png");
    public final static ResourceLocation PROCESS = new ResourceLocation(Fracdustry.MODID, "textures/gui/ore_processor/process_bar.png");


    private final IDrawable background;
    private final IDrawable icon;
    private final IDrawable processBar;

    public OreProcessorRecipeCategory(IGuiHelper helper) {
        this.background = helper.createDrawable(BACKGROUND, 0, 0, 180, 68);
        this.icon = helper.createDrawableIngredient(new ItemStack(FDBlocks.blockOreProcessor.get()));
        this.processBar = helper.createDrawable(PROCESS, 0, 0, 33, 4);
    }

    @Nonnull
    @Override
    public ResourceLocation getUid() {
        return UID;
    }

    @Nonnull
    @Override
    public Class<? extends OreProcessorRecipe> getRecipeClass() {
        return OreProcessorRecipe.class;
    }

    @Nonnull
    @Override
    public Component getTitle() {
        return FDBlocks.blockOreProcessor.get().getName();
    }

    @Nonnull
    @Override
    public IDrawable getBackground() {
        return this.background;
    }

    @Nonnull
    @Override
    public IDrawable getIcon() {
        return this.icon;
    }

    @Override
    public void setIngredients(OreProcessorRecipe recipe, IIngredients ingredients) {
        ingredients.setInputIngredients(recipe.getIngredients());
        ingredients.setOutput(VanillaTypes.ITEM, recipe.getResultItem());
    }

    @Override
    public void setRecipe(IRecipeLayout recipeLayout, @Nonnull OreProcessorRecipe recipe, @Nonnull IIngredients ingredients) {
        recipeLayout.getItemStacks().init(0, true, 53, 25);

        recipeLayout.getItemStacks().init(1, false, 110, 25);
        recipeLayout.getItemStacks().set(ingredients);
    }

    @Override
    public void draw(@Nonnull OreProcessorRecipe recipe, @Nonnull PoseStack matrixStack, double mouseX, double mouseY) {
        this.processBar.draw(matrixStack, 74, 32);
    }
}
